package de.breitbeil.jbooking.ui.form;

import java.util.Calendar;
import java.util.Date;

import org.springframework.binding.form.FormModel;
import org.springframework.richclient.settings.Settings;

import de.breitbeil.jbooking.ui.preferences.SettingsFormObject;

public class SaveCalendarFormObject implements SettingsFormObject {

    private String filename;
    private String suffix;
    private Date firstDisplayedDay;
    
    public String getFilename() {
        return filename;
    }
    public void setFilename(String filename) {
        this.filename = filename;
    }
    public String getSuffix() {
        return suffix;
    }
    public void setSuffix(String suffix) {
        this.suffix = suffix;
    }
    public void setFirstDisplayedDay(Date firstDisplayedDay) {
        this.firstDisplayedDay = firstDisplayedDay;
    }
    public Date getFirstDisplayedDay() {
        return firstDisplayedDay;
    }
    
    public void init(Settings settings) {
        filename = settings.getString("calendar.filename");
        suffix = settings.getString("calendar.suffix");
        firstDisplayedDay = Calendar.getInstance().getTime();
    }
    
    public void save(Settings settings) {
        settings.setString("calendar.filename", filename);
        settings.setString("calendar.suffix", suffix);
    }
    
    public void fillDefaults(FormModel formModel) {
        String userHome = System.getProperty("user.home") + System.getProperty("file.separator");
        String year = Calendar.getInstance().get(Calendar.YEAR)+"";
        
        formModel.getValueModel("filename").setValue(userHome + "JBookingCalendar.jpg");
        formModel.getValueModel("suffix").setValue("jpg");
        formModel.getValueModel("year").setValue(year);
    }
}
